package conf

import (
	"gopkg.in/yaml.v3"
	"log"
	"os"
)

var (
	C Conf
)

type Conf struct {
	ModbusRtu ModbusRtu `yaml:"modbus-rtu"`
}

type ModbusRtu struct {
	Serial struct {
		PortName string `yaml:"port-name"`
		Baud     int    `yaml:"baud"`
		StopBits int    `yaml:"stop-bits"`
	}
	Tcp struct {
		Host string `yaml:"host"`
		Port int    `yaml:"port"`
	}
}

func Init() {

	//conf := Conf{}
	yamlFile, err := os.ReadFile("F:\\dev\\code_go\\src\\iot-protocol-oob\\conf\\conf.yaml")
	if err != nil {
		log.Printf("yamlFile.Get err   #%v ", err)
	}

	err = yaml.Unmarshal(yamlFile, &C)
	if err != nil {
		log.Fatalf("Unmarshal: %v", err)
	}

}
